package thread.system12306;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class System12306 {

    private List<Ticket> vector = new ArrayList<>();

  //  private Vector<Ticket> vector = new Vector<>();
    //垃圾饿汉式单例模式
  private static System12306 instance=new System12306();
    private System12306(){
        for(int i = 10; i < 100; i++){
            Ticket ticket = new Ticket("北京"+i,"梁山"+i,(i%5+5)*25F);
            vector.add(ticket);
        }
    }
    public static System12306 getInstance(){
        return instance;
    }








    public  Ticket getTicket(){

        try {
            synchronized(vector){
                Ticket t = vector.remove(0);
                return t;
            }

        }catch (Exception e){
            return null;
        }
    }


}
